/*
 * @Author: jiu yin
 * @Date: 2024-06-11 13:54:10
 * @LastEditTime: 2024-06-19 11:59:21
 * @LastEditors: jiu yin zhen jing
 * @FilePath: \studio-web-admin\electron\main.cjs
 * jiu
 */
const { app, BrowserWindow, Menu, screen, globalShortcut } = require('electron');
const path = require('path');
let mainWindow;

function createWindow() {
  const mainScreen = screen.getPrimaryDisplay();
  const dimensions = mainScreen.size;

  mainWindow = new BrowserWindow({
    width: dimensions.width,
    height: dimensions.height,
    webPreferences: {
      nodeIntegration: true,
      contextIsolation: false
    },
    icon: path.join(__dirname, '../public/logo.png')
  });

  Menu.setApplicationMenu(null) // null值取消顶部菜单栏
  mainWindow.webContents.on('will-attach-webview', (event, webPreferences) => {
    webPreferences.nodeIntegration = true;
    webPreferences.webviewTag = true;
  });
  mainWindow.loadURL(`http://studio.ym2meta.com`);

  // 监听 F5 键
  globalShortcut.register('F5', () => {
    // 执行刷新操作
    mainWindow.reload();
  });
  
  mainWindow.on('closed', () => {
    mainWindow = null;
  });
}

app.on('ready', async () => {

  createWindow();
});

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit();
  }
});

app.on('activate', () => {
  if (mainWindow === null) {
    createWindow();
  }
});